<template>
  <div class="battery">
    <div class="number">{{ process }}%</div>
    <div class="contrast">
      <div class="bubble" />
      <div class="bubble" />
      <div class="bubble" />
      <div class="bubble" />
      <div class="bubble" />
      <div class="bubble-home" />
      <div class="circle" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'Animation',
  props: {
    process: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {}
  }
}
</script>
<style scoped lang="scss">
.battery {
  width: 100%;
  height: 100%;

  /* 充电百分比 */
  .number {
    position: absolute;
    top: 25%;
    left: 50%;
    z-index: 1;
    width: 200px;
    height: 200px;
    margin-left: -100px;
    font-size: 30px;
    line-height: 200px;
    color: #fff;
    text-align: center;
  }

  .contrast {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: #000;

    /* 设置对比度 */
    filter: contrast(15);

    /* 指定动画：动画名 时长 线性的 无限次播放 */
    animation: hueRotate 5s linear infinite;
  }

  /* 变色动画 */
  @keyframes hueRotate {
    0% {
      /* contrast是设置对比度，hue-rotate是颜色滤镜 通过设置度数来改变颜色 */
      filter: contrast(15) hue-rotate(0);
    }

    100% {
      filter: contrast(15) hue-rotate(360deg);
    }
  }

  .circle {
    position: absolute;
    top: 20%;
    left: 50%;
    width: 300px;
    height: 300px;
    margin-left: -150px;

    /* 设置模糊度，配合上面的contrast可以产生粘性效果 */
    filter: blur(8px);

    /* 执行动画 */
    animation: circleRotate 2s linear infinite;
  }

  /* 外圈 */
  .circle::before {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200px;
    height: 200px;
    content: '';
    background-color: cyan;
    border-radius: 42% 38% 63% 49% / 45%;
    transform: translate(-50%, -50%);
  }

  /* 中心圆（黑色） */
  .circle::after {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 178px;
    height: 178px;
    content: '';
    background-color: #000;
    border-radius: 50%;
    transform: translate(-50%, -50%);
  }

  /* 圆旋转动画 */
  @keyframes circleRotate {
    0% {
      transform: rotate(0);
    }

    100% {
      transform: rotate(360deg);
    }
  }

  /* 冒泡的底座 */
  .bubble-home {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 100px;
    height: 40px;
    margin-left: -50px;
    background-color: cyan;
    filter: blur(8px);
    border-radius: 100px 100px 0 0;
  }

  .bubble {
    position: absolute;
    bottom: 0;
    left: 50%;
    z-index: 2;
    width: 20px;
    height: 20px;
    background-color: cyan;
    filter: blur(5px);
    border-radius: 100%;
    transform: translateX(-50%);

    /* 执行动画：动画名 时长 加速后减速 无限次播放 */
    animation: bubbleUp 1s ease-in-out infinite;
  }

  /* 接下来分别为每一个泡泡设置大小、位置、动画时长、动画延迟时间 */
  .bubble:nth-child(1) {
    left: 50%;
    width: 20px;
    height: 20px;
    animation-duration: 1s;
    animation-delay: 0.1s;
  }

  .bubble:nth-child(2) {
    left: 49%;
    width: 22px;
    height: 22px;
    animation-duration: 2s;
    animation-delay: 2s;
  }

  .bubble:nth-child(3) {
    left: 47%;
    width: 24px;
    height: 24px;
    animation-duration: 3s;
    animation-delay: 1s;
  }

  .bubble:nth-child(4) {
    left: 53%;
    width: 18px;
    height: 18px;
    animation-duration: 2s;
    animation-delay: 3s;
  }

  .bubble:nth-child(5) {
    left: 51%;
    width: 26px;
    height: 26px;
    animation-duration: 3s;
    animation-delay: 2s;
  }

  /* 冒泡动画 */
  @keyframes bubbleUp {
    0% {
      bottom: 0;
    }

    100% {
      bottom: calc(80% - 260px);
    }
  }

  .animate__animated {
    --animate-duration: 5s;
  }
}
</style>
